package com.sxz.sbs.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 预约时间工具类
 */

public class AppointTimeUtils {
    private static final long ONE_DAY_MS = 24 * 60 * 60 * 1000;
    private  List<String> list = new ArrayList<>();
    public List<String> setTime() {
        List<String> timeList = new ArrayList<>();
        Calendar calendar2 = Calendar.getInstance();
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
        calendar2.add(Calendar.DATE, 6);
        String three_days_after = sdf2.format(calendar2.getTime());
        try {
            timeList =   betweenDays(System.currentTimeMillis(), sdf2.parse(three_days_after).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timeList;
    }
    /**
     * 获取两个时间戳之间的所有日期
     *
     * @param startTime
     * @param endTime
     */
    private  List<String> betweenDays(long startTime, long endTime) {
        Date date_start = new Date(startTime);
        Date date_end = new Date(endTime);
        //计算日期从开始时间于结束时间的0时计算
        Calendar fromCalendar = Calendar.getInstance();
        fromCalendar.setTime(date_start);
        fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
        fromCalendar.set(Calendar.MINUTE, 0);
        fromCalendar.set(Calendar.SECOND, 0);
        fromCalendar.set(Calendar.MILLISECOND, 0);
        Calendar toCalendar = Calendar.getInstance();
        toCalendar.setTime(date_end);
        toCalendar.set(Calendar.HOUR_OF_DAY, 0);
        toCalendar.set(Calendar.MINUTE, 0);
        toCalendar.set(Calendar.SECOND, 0);
        toCalendar.set(Calendar.MILLISECOND, 0);
        int s = (int) ((toCalendar.getTimeInMillis() - fromCalendar.getTimeInMillis()) / (ONE_DAY_MS));
        if (s > 0) {
            for (int i = 0; i <= s; i++) {
                long todayDate = fromCalendar.getTimeInMillis() + i * ONE_DAY_MS;
                //获取所有时间
                list.add(getDate(todayDate));
            }
        }
        return list;
    }
    /**
     * 时间戳换字符串
     * @param time
     * @return
     */
    public  String getDate(long time) {
        Date date = new Date(time);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd EEEE");
        return format.format(date);
    }
}
